package StringDemo.TraverceString;

public class ComplexExample {
    public static void main(String[] args) {
        String result = arrToString(intToArr(12323));
        System.out.println(result);
    }

    public static int[] intToArr(int money) {
        int[] moneyArr = new int[8];
        for (int i = moneyArr.length -1 ; i >= 0; i--) {
            moneyArr[i] = money % 10;
            money /= 10;
        }
        return moneyArr;
    }

    public static String arrToString(int[] moneyArr) {
        String result = "";
        char[] moneyChar1 = {'零','壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'};
        String[] moneyChar2 = {"","拾","佰","仟"};
        char[] resultPart = new char[8];
        for (int i = 0; i < resultPart.length; i++) {
            resultPart[i] = moneyChar1[moneyArr[i]];
        }
        for (int i = 0; i < resultPart.length; i++) {
            result += resultPart[i];
            result += moneyChar2[(resultPart.length - i - 1) % 4];
            if(resultPart.length - i == 5)
                result += '万';
        }
        return result;
    }
}
